package admin

type Resource struct {
	Label      string      `json:"label"`
	Name       string      `json:"name"`
	Type       string      `json:"type,omitempty"`
	Url        string      `json:"url,omitempty"`
	Icon       string      `json:"icon,omitempty"`
	Sort       uint        `json:"sort,omitempty"`
	Schema     interface{} `json:"schema,omitempty"`
	SchemaApi  interface{} `json:"schemaApi,omitempty"`
	Children   []Resource  `json:"children,omitempty"`
	PermList   PermList    `json:"permList,omitempty"`
	ParentName string      `json:"parentName,omitempty"`
}

type Floder struct {
	Resource
	Modules []IModule
}

func NewFloder(label, name, icon string, sort uint) Floder {
	return Floder{
		Resource: Resource{
			Label: label,
			Name:  name,
			Icon:  icon,
			Sort:  sort,
		},
	}

}

func (r Floder) AddModule(modules ...IModule) IModule {
	for _, m := range modules {
		if _, ok := m.(IFloder); ok {
			panic("目前目录只支持一层，不支持多层嵌套")
		}
	}
	r.Modules = append(r.Modules, modules...)
	return r
}

func (r Floder) GetResource() Resource {
	return r.Resource
}

func (r Floder) GetChildren() []IModule {
	return r.Modules
}

func (r Floder) GetApiUrl(path string) string {
	return r.Url + path
}

func (r Floder) GetRouterPath(path string) string {
	return "/" + r.Name + "/" + path
}
